package com.atguigu.wordcount.groupcomparator;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @ClassName Order
 * @DeScription Order
 * @Author 剧情再美终是戏
 * @Date 2019/11/19 15:13
 * @Version 1.0
 **/
// 10000001	Pdt_01	222.8
public class Order implements WritableComparable<Order> {

    private String id;

    private String pid;

    private Double price;


    public int compareTo(Order o) {
        int result = this.getId().compareTo(o.getId());
        if (result == 0) {
            result = -this.getPrice().compareTo(o.getPrice());
        }
        return result;
    }

    public void write(DataOutput out) throws IOException {
        out.writeUTF(id);
        out.writeUTF(pid);
        out.writeDouble(price);
    }

    public void readFields(DataInput in) throws IOException {
        id = in.readUTF();
        pid = in.readUTF();
        price = in.readDouble();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return id + "\t" + pid + "\t" + price;
    }
}
